package com.xc.ezplan.admin.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.xc.ezplan.admin.service.AdminQiniuConfigService;
import com.xc.ezplan.admin.vo.AdminQiniuConfigVo;
import com.xc.ezplan.core.base.EzResult;
import com.xc.ezplan.log.annotation.Log;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author lixingchen
 * @date 2022/12/4
 * @description
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/qiNiu/config")
@Api(tags = "七牛云配置")
public class AdminQiNiuConfigController {
	private final AdminQiniuConfigService adminQiniuConfigService;

	@Log("新增七牛云配置")
	@ApiOperation("新增七牛云配置")
	@PostMapping
	@SaCheckPermission("qiniu.config.add")
	public EzResult<Object> createQiNiuConfig(@Validated @RequestBody AdminQiniuConfigVo adminQiniuConfigVo) {
		adminQiniuConfigService.createQiNiuConfig(adminQiniuConfigVo);
		return EzResult.ok();
	}

	@Log("更新七牛云配置")
	@ApiOperation("更新七牛云配置")
	@PutMapping
	@SaCheckPermission("qiniu.config.update")
	public EzResult<Object> updateQiNiuConfig(@Validated @RequestBody AdminQiniuConfigVo adminQiniuConfigVo) {
		adminQiniuConfigService.updateQiNiuConfig(adminQiniuConfigVo);
		return EzResult.ok();
	}

	@Log("删除七牛云配置")
	@ApiOperation("删除七牛云配置")
	@DeleteMapping
	@SaCheckPermission("qiniu.config.delete")
	public EzResult<Object> deleteQiNiuConfig(@RequestBody List<Long> ids) {
		adminQiniuConfigService.deleteQiNiuConfig(ids);
		return EzResult.ok();
	}

	@ApiOperation("查看七牛云配置")
	@GetMapping
	public EzResult<Object> queryQiNiuConfig(@RequestParam Long id) {
		return EzResult.ok(adminQiniuConfigService.queryQiNiuConfig(id));
	}

	@ApiOperation("按条件查询配置")
	@PostMapping("/all")
	public EzResult<Object> queryAllQiNiuConfig(@RequestBody(required = false) String keyWord){
		return EzResult.ok(adminQiniuConfigService.queryAllQiNiuConfig(keyWord));
	}
}
